let app = getApp()
var wxCharts = require('../../../../utils/wxcharts2.js');
Component({
    properties: {
      cus_id:Number
      },
      data:{
        loginShow:false,
        cWidth: "",
        cHeight: "",
        pixelRatio: 1,
        chartData: {
          categories: [],
          series: [ {
          name: "近15天客户活跃度",
          data: [],
          color: "#3A82F8"
          } ]
        },
        chartData1: {
          categories: [ "拨打电话", "分享文章", "分享产品", "查看文章", "查看产品" ],
            series: [ {
                  name: "客户与我的互动",
                  data: []
                    } ]
              },
         info: ""
      },
    lifetimes: {
        attached: function () {
              this.data1()
         }
      },
    methods: {
        data1:function(){
          var that=this
          wx.request({
            url: app.globalData.siteroot,
             data: {
               do:'Customer_aiChart',
               staff_id:wx.getStorageSync('staff_bind_id'),
               cus_id:that.data.cus_id
            },
           success: function(res) {
               that.OnWxChart('canvasLineA','line',res.data.info.active.date,res.data.info.active.count)
               var data2=[res.data.info.interaction.dial_cnt,
                res.data.info.interaction.share_article_cnt,
                res.data.info.interaction.share_product_cnt,
                res.data.info.interaction.view_article_cnt,
                res.data.info.interaction.view_product_cnt
                ]
               that.data.chartData1.series[0].data.push(res.data.info.interaction)
               that.OnWxChart('canvasColumn','column',that.data.chartData1.categories,data2)
           }
          })
        },
        OnWxChart:function(canvasId,type,x_data,y_data){
          var windowWidth = '', windowHeight='';
          try {
            var res = wx.getSystemInfoSync();  
            windowWidth = res.windowWidth / 750 * 690; 
            windowHeight = res.windowWidth / 750 * 550  
          } catch (e) {
            console.error('getSystemInfoSync failed!');
          }
          new wxCharts({
            canvasId: canvasId,
            type:type,     
            categories:x_data,
            animation: true,
            series: [{
              data: y_data,
              format: function (val, name) {
                return val + '次';
              }
            }
            ],
            xAxis: {
              disableGrid: true,
            },
            yAxis: { 
              title: '',
              format: function (val) {
                if(type=='line'){
                  return val + '次';
                }else{
                  return val*10;
                }
              },
              min:0, 
              max:1,
              gridColor: '#D8D8D8',
            },
            width: windowWidth*1.1,
            height: windowHeight,
            dataLabel: true,
            dataPointShape: true,
            extra: {
              lineStyle: 'Broken'
            }
        },this);
        }
      
    }
});
